/**
  ******************************************************************************
  * @file    main.c
  * @author  AE Team
  * @version 1.0.3
  * @date    2024-05-28
  * @brief   本样例演示以最快的速度翻转IO(LED所在端口PA03)， 用户可以选择三种方式对IO进行操作：
  *          1：通过BSRR和BRR寄存器操作IO
  *          2：通过TOG寄存器操作IO
  *          3：通过ODR寄存器操作IO
  *          用户可以通过宏 TEST_GPIO_SELECT 选择上述三种方式中的任一种进行测试。
  *          本演示样例会在PB03端口输出系统时钟 MCO=HCLK, 用户可以用示波器观察PB03和(LED)PA03的时钟输出，
  *          可以看到每2个系统时钟就会翻转一次IO。
  *
  * @note    硬件平台：SYM32L010_StartKit_V1.0
  *          接线说明：None
  *
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2024 SIYIMicro.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */


/******************************************************************************/
/* Include files                                                              */
/******************************************************************************/
#include "main.h"
#include "sym32l010_hal_sysctrl.h"
#include "sym32l010_hal_systick.h"
#include "sym32l010_hal_gpio.h"
#include "sym32l010_startkit_board.h"


/******************************************************************************/
/* Local pre-processor symbols/macros ('#define')                             */
/******************************************************************************/

#define TEST_GPIO_BSRR       1U
#define TEST_GPIO_TOG        2U
#define TEST_GPIO_ODR        3U

#define TEST_GPIO_SELECT     TEST_GPIO_TOG                            // 具体选择哪种模式由用户自行选择


/******************************************************************************/
/* Global variable definitions (declared in header file with 'extern')        */
/******************************************************************************/

/******************************************************************************/
/* Local type definitions ('typedef')                                         */
/******************************************************************************/

/******************************************************************************/
/* Local function prototypes ('static')                                       */
/******************************************************************************/

/******************************************************************************/
/* Local variable definitions ('static')                                      */
/******************************************************************************/

/******************************************************************************/
/* Local pre-processor symbols/macros ('#define')                             */
/******************************************************************************/

/******************************************************************************/
/* Function implementation - global ('extern') and local ('static')           */
/******************************************************************************/


/*******************************************************************************
 ** \brief  Main function of project
 **
 ** \return uint32_t return value, if needed
 **
 **
 ******************************************************************************/
int32_t main(void)
{
    // 初始化SysTick
    HAL_InitTick(4000000);

    // 在PB03管脚输出HCLK时钟
    HAL_SysCtrl_ClkOut_MCO_PB03(SYSCTRL_MCO_SRC_HCLK, SYSCTRL_MCO_DIV1);

    // 初始化板载LED
    Bsp_Led_Init();

    while (1)
    {
      #if (TEST_GPIO_SELECT == TEST_GPIO_BSRR)
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
        BSP_LED_PORT->BSRR = BSP_LED_PIN;
        BSP_LED_PORT->BRR  = BSP_LED_PIN;
      #elif (TEST_GPIO_SELECT == TEST_GPIO_TOG)
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
        BSP_LED_PORT->TOG = BSP_LED_PIN;
      #elif (TEST_GPIO_SELECT == TEST_GPIO_ODR)
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
        BSP_LED_PORT->ODR = BSP_LED_PIN;
        BSP_LED_PORT->ODR = 0;
      #endif
    }
}


/*******************************************************************************
 ** EOF (not truncated)
 ******************************************************************************/
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
    /* USER CODE BEGIN */
    /* User can add his own implementation to report the file name and line number,
       tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    /* USER CODE END */
}
#endif /* USE_FULL_ASSERT */


/************************ (C) COPYRIGHT SIYIMicro *****END OF FILE*************/
